<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
    <title>Document</title>
    <style>
        .main{
            height: 3000px;
        }
        .main div{
            height: 100px;
            width: 100px;
        }
        #head{
            background-color: royalblue;
        }
        #middle{
            margin-top: 800px;
            background-color: red;
        }
        #foot{
            margin-top: 800px;
            background-color: aqua;
        }
    </style>
</head>
<body>
    <p>
        <a href="#head">head</a>
        <a href="#middle">middle</a>
        <a href="#foot">foot</a>
    </p>
    <div class="main">
        <div id="head"></div>
        <div id="middle"></div>
        <div id="foot"></div>
    </div>
    <script>
        $("p a").click(function(){
            let id = $(this).attr("href");
            let top = $(id).offset().top;
            $("html").animate({scrollTop:top},1000);
        })
    </script>
</body>
</html>